package br.unicamp.ic.inf312.arena.persistencia.dao.impl;

import br.unicamp.ic.inf312.arena.modelo.logistico.Sala;
import br.unicamp.ic.inf312.arena.modelo.logistico.SalaCinema;
import br.unicamp.ic.inf312.arena.modelo.logistico.SalaConfiguravel;
import br.unicamp.ic.inf312.arena.persistencia.dao.ISalaDAO;
import br.unicamp.ic.inf312.framework.persistencia.SQLUtil;

public class SalaDAOMySQL implements ISalaDAO {

	/**
	 * 
	 */
	public Sala obterSala(int codigo, int tipo) throws Exception {
		Sala sala = null;

		Object[] params = new Object[1];
		params[0] = codigo;

		StringBuffer stbQuery = new StringBuffer();
		stbQuery.append(" SELECT * FROM ");
		stbQuery.append(SQLUtil.getDbSchema() + "." + ISalaDAO.TABELA_BD);
		stbQuery.append(" WHERE " + ISalaDAO.COLUMN_CODIGO_PK + " = ?");

		if (tipo == Sala.TIPO_CONFIGURAVEL) {
			sala = new SalaConfiguravel();
			sala = (Sala) SQLUtil.retrieveBean(stbQuery.toString(),
					SalaConfiguravel.class, params);
		} else if (tipo == Sala.TIPO_CINEMA) {
			sala = new SalaCinema();
			sala = (Sala) SQLUtil.retrieveBean(stbQuery.toString(),
					SalaCinema.class, params);
		}

		return sala;
	}
}